package com.neusoft.edu.smartschool.app.parttern.presenter;

import android.content.Intent;
import android.view.View;

import com.neu.edu.smartschool.mapplication.R;
import com.neusoft.edu.smartschool.app.db.sp.UserSp;
import com.neusoft.edu.smartschool.app.entity.UserBean;
import com.neusoft.edu.smartschool.app.parttern.model.LoginModel;
import com.neusoft.edu.smartschool.app.parttern.other.ThreadPoolProxyFactory;
import com.neusoft.edu.smartschool.app.parttern.view.ILoginView;

import org.yeruyi.common.abs.AbsRoyModel;
import org.yeruyi.common.inter.RoyBaseView;
import org.yeruyi.common.presenter.RoyBasePresenter;

/**
 * @author: yeruyi
 * @date: 2018/5/29
 * @email: yeruyi_roy@outlook.com
 * @modify: 2018/5/29 创建文件
 */
public class LoginPresenter extends RoyBasePresenter<ILoginView> implements View.OnClickListener {

    private LoginModel mModel;

    public LoginPresenter(ILoginView view) {
        super(view);
        mModel = new LoginModel();
    }


    @Override
    public void onViewInit() {

    }

    @Override
    public void onViewReady(Intent intent) {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.login_enter_bt: {
                reqLogin();
                break;
            }
        }
    }

    private void reqLogin() {
        String stuNum = mView.getLoginName();
        String stuPwd = mView.getLoginPwd();
        if (stuNum.isEmpty() || stuPwd.isEmpty()) {
            return;
        }
        mModel.reqLogin(stuNum, stuPwd, new AbsRoyModel.INetCallBack<UserBean>() {
            @Override
            public void success(final UserBean data) {
                // 记录用户数据
//                ThreadPoolProxyFactory.getSaveThreadPoolProxy().execute(new Runnable() {
//                    @Override
//                    public void run() {
//
//                    }
//                });
                UserSp.getInstance(mView.getActivityContext()).setUserBean(data);
                // 请求跳转主页

            }

            @Override
            public void failed(String msg) {
                mView.showToast(msg);
            }
        });
    }
}
